﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

public partial class UserControl_phong_tro_tim_kiem_nhanh : System.Web.UI.UserControl
{
    protected string strClassName = "UserControl_phong_tro_tim_kiem_nhanh";
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            xgetTinhThanh();
            xgetKieuPhong();
            xSetValueFromUrl();
        }

    }

    /// <summary>
    /// Lấy danh sách tỉnh thành trên toàn quốc
    /// Author: Nguyen7huan
    /// Create: 26/09/2013
    /// </summary>
    private void xgetTinhThanh()
    {
        try
        {
            DataTable dt = clsKhuVuc.fncGetKhuVucBy_ParentID("0");
            if (dt == null) { return; }
            if (dt.Rows.Count <= 0) { return; }

            for (int i = 0; i < dt.Rows.Count; i++)
            {
                ListItem lstTinhThanh = new ListItem { Text = dt.Rows[i]["KV_TEN"].ToString(), Value = dt.Rows[i]["KV_ID"].ToString() };
                lstTinhThanh.Attributes.Add("ten-ko-dau", dt.Rows[i]["KV_TENKHONGDAU"].ToString().ToLower());
                ddlTinhThanh.Items.Add(lstTinhThanh);
            }
        }
        catch (Exception ex)
        {
            OsPortal.oFileHelper.WriteLogErr(strClassName, "getKieuPhong", ex.ToString());
        }
    }
    /// <summary>
    /// Lấy danh sách kiểu phòng trọ
    /// </summary>
    private void xgetKieuPhong()
    {
        try
        {
            ddlChuyenMuc.DataSource = clsKieuPhongTro.fncKieuPhongTro_FND("", "");
            ddlChuyenMuc.DataTextField = "kp_ten";
            ddlChuyenMuc.DataValueField = "kp_tenkhongdau";
            ddlChuyenMuc.DataBind();

        }
        catch (Exception ex)
        {
            OsPortal.oFileHelper.WriteLogErr(strClassName, "getKieuPhong", ex.ToString());
        }
    }

    /// <summary>
    /// Lấy giá trị trên url và đặt lại cho các control
    /// Author: ThuanNH
    /// Create: 15/10/2013
    /// </summary>
    private void xSetValueFromUrl()
    {
        ddlChuyenMuc.SelectedValue = clsCommon.fncGetRoute(this.Page, "userControl");
        //
        string strKhuVuc = clsCommon.fncGetRoute(this.Page, "param1");
        if (clsKhuVuc.fncCheckParentKhuVuc(strKhuVuc))
        {
            ddlTinhThanh.SelectedValue = clsKhuVuc.fncGet_ID_KhuVucBy_TenKodau(strKhuVuc);
        }
        else
        {
            ddlTinhThanh.SelectedValue = clsKhuVuc.fncGetValue_DetailKV_By_TenKD(strKhuVuc, "KV_PARENTID");
            hdQuanHuyen_Search.Value = strKhuVuc.ToLower();
        }
        //
        ddlGiaPhong.SelectedValue = clsCommon.fncGetRoute(this.Page, "param2");
        ddlDienTich.SelectedValue = clsCommon.fncGetRoute(this.Page, "param3");
    }

}